<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace api\modules\v1\controllers;
use Yii;
use backend\module\content\models\ContentCategory;
/**
 * Description of RecommondController
 *
 * @author zhuo bing
 */
class RecommendsController extends BaseController{
    public function actionIndex(){
        $currTimeSec = time()-strtotime('today');
        $request = Yii::$app->request;
        $cid = $request->get('cid',0);
        $catInfo = ContentCategory::findOne($cid);
        if($catInfo){
            $modelClass = "\\api\models\\".$catInfo['controller'];
            $data = $modelClass::find(['cid'=>$cid])
                    ->andWhere(['>','time_to_sec(shop_hours_start)',$currTimeSec])
                    ->andWhere(['<','time_to_sec(shop_hours_end)',$currTimeSec])
                    ->select('id,thumb')->limit(5)->asArray()->all();
            return $data;
        }
    }
}
